﻿#include "CenterAuctioneerMgr.h"
#include "base/core/com_define.h"
#include "CenterService.h"
#include "Active/ActiveCharacterMgr.h"
#include "base/core/os/time.h"
#include "base/core/log.h"
#include "MailCenter/MailManager.h"
#include "Common/TableData/EquipEquipCfg.h"
#include "Common/TableData/ItemItemCfg.h"
#include "Common/TableData/ConstantConstantCfg.h"
#include "Common/TableData/FunctionunlockFunctionUnlockCfg.h"
#include "RelationMgr/RelationMgr.h"
#include "Common/PackageDefine.h"
#include "Common/ComDefine.pb.h"
#include "Cache/OfflineCharacterDataMgr.h"
#include "Common/LogDefine.h"
const uint32_t g_constPageCount = 4;
const uint32_t g_constMaxSaleItem = 20;
CCenterAuctioneerMgr::CCenterAuctioneerMgr()
{
	m_auctioneerItemPool = new ObjectPool<CAuctioneerItem>(200, false);
	//初始化类型map
	for (int i = AuctioneerFilterItemReq::DaJian; i <= AuctioneerFilterItemReq::OtherItem; ++i)
	{
		AUCTIONEERTYPELEVEL maplevel;
		m_mapTypeItem[i] = maplevel;
	}

}

CCenterAuctioneerMgr::~CCenterAuctioneerMgr()
{
	MMO_DELETE(m_auctioneerItemPool);
	
	g_GetTimerAxis()->KillAllTimer(this);
}


bool CCenterAuctioneerMgr::Init()   //做些初始化工作
{
	g_GetActiveCharacterMgr()->AddCharacterObserver(this);

	IMessageDispatch *pMessageDispatch = g_GetCenterService()->GetServiceMessageDispatch();
	if (nullptr == pMessageDispatch)
	{
		MMOLOG_FMT_ERROR("[center] MailManager::Init....nullptr == pMessageDispatch ");
		return false;
	}


	pMessageDispatch->registerDBProxyHandler(EMODULE_ID_AUCTIONEER, this);
	pMessageDispatch->registerClientHandler(EMODULE_ID_AUCTIONEER, this);
	pMessageDispatch->registerServerHandler(EMODULE_ID_AUCTIONEER, this);


	for (int i = AuctioneerFilterItemReq::DaJian; i < AuctioneerFilterItemReq::en_Sub_Type; ++i)
	{
		if (i<=AuctioneerFilterItemReq::GongJian && i>= AuctioneerFilterItemReq::DaJian)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_Equip].push_back(i);
		}
		else if (i> AuctioneerFilterItemReq::GongJian && i <= AuctioneerFilterItemReq::XueZi)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_Defend].push_back(i);
		}
		else if (i>AuctioneerFilterItemReq::XueZi && i <= AuctioneerFilterItemReq::HuFu)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_Jewelry].push_back(i);
		}
		else if (i > AuctioneerFilterItemReq::HuFu && i < AuctioneerFilterItemReq::BuffYaoShui)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_YaoShui].push_back(i);
		}
		else if (i>=AuctioneerFilterItemReq::BuffYaoShui && i <= AuctioneerFilterItemReq::JuanZhou)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_ByWork].push_back(i);
		}
		else if (i > AuctioneerFilterItemReq::JuanZhou && i <= AuctioneerFilterItemReq::EquipZhiTu)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_YangCheng].push_back(i);
		}
		else if (i >AuctioneerFilterItemReq::EquipZhiTu && i <= AuctioneerFilterItemReq::JinLinSkillBook)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_Pet].push_back(i);
		}
		else if (i == AuctioneerFilterItemReq::OtherItem)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_Other].push_back(i);
		}
		else if (i == AuctioneerFilterItemReq::GuanZhu)
		{
			m_mapBigType[AuctioneerFilterItemReq::en_Big_GuanZhu].push_back(i);
		}
	}

	//开始加载离线数据定时器
	bool ret = g_GetTimerAxis()->SetTimer(enSystemTimeID_RequestDB, 2 * 1000, this);
	return ret;
	//return true;
}

bool CCenterAuctioneerMgr::UnInit()
{
	g_GetActiveCharacterMgr()->RemoveCharacterObserver(this);
	IMessageDispatch *pMessageDispatch = g_GetCenterService()->GetServiceMessageDispatch();
	if (nullptr != pMessageDispatch)
	{
		pMessageDispatch->unregisterDBProxyHandler(EMODULE_ID_AUCTIONEER);
		pMessageDispatch->unregisterClientHandler(EMODULE_ID_AUCTIONEER);
		pMessageDispatch->unregisterServerHandler(EMODULE_ID_AUCTIONEER);
	}

	AUCTIONITEMMAP::iterator iter = m_mapItem.begin();
	for (; iter != m_mapItem.end();++iter)
	{
		iter->second->Unit();
		m_auctioneerItemPool->FreeObj(iter->second);
	}
	m_mapItem.clear();

	//AUCTIONTYPEFOCUSMAP::iterator iterFocus=m_focusMap.begin();
	//for (; iterFocus != m_focusMap.end(); ++iterFocus)
	//{
	//	delete iterFocus->second;
	//}
	m_focusMap.clear();
	MMO_DELETE(m_auctioneerItemPool);
	return true;
}


void CCenterAuctioneerMgr::onCharacterLogin(ActiveCharacter *pOnlineCharacter)
{
	//上线，向DB去取关注列表
	AuctioneerGetFocusListReq req;
	req.set_charid(pOnlineCharacter->GetCharID());
	g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_GET_FOCUS_LIST_REQ, &req);
}
//角色登出
void CCenterAuctioneerMgr::onCharacterLogout(ActiveCharacter *pOnlineCharacter)
{
	//把玩家关注列表删除
	AUCTIONTYPEFOCUSMAP::iterator iter = m_focusMap.find(pOnlineCharacter->GetCharID());
	if (iter!=m_focusMap.end())
	{
		m_focusMap.erase(iter);
	}
}


void CCenterAuctioneerMgr::onCharacterDel(OfflineCharacterData *pInfo)
{
	//角色删除时，把所有该玩家上架的物品下架
	AUCTIONITEMMAP::iterator  iter = m_mapItem.begin();
	for (; iter != m_mapItem.end(); ++iter)
	{
		if (iter->second->GetSaleID() == pInfo->GetCharID())
		{

			AuctioneerDeletItemRequest sendmsg;
			sendmsg.set_id(iter->second->GetGlobelId());
			g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);

			SendAuctioneerOperateLog(iter->second->GetSaleID(), iter->second, iter->second->GetNum(), EnAuctioneerOperateType_SystemSaleOut);

			PopItemTypeMap(iter->second->GetItemInfo()->item_id(), iter->second->GetGlobelId());
		}			
	}
}


void		CCenterAuctioneerMgr::onServerMessage(uint32_t actionId, RECV_PACKAGE &package)
{
	switch (actionId)
	{
	case LOGIC_TO_CENTER_AUCTIONEER_REDUCE_MONEY_RESULT:
		OnRecReduceMoneyFromLogic(package);
		break;
	case LOGIC_TO_CENTER_AUCTIONEER_SALE_ITEM:
		OnRecAddItemListFromLogic(package);
		break;
	default:
		break;
	}
}
void CCenterAuctioneerMgr::OnRecAddItemListFromLogic(RECV_PACKAGE &package)
{
	LogicToCenterAuctioneerSale req;
	CenterToLogicAuctioneerSaleResult rsp;
	AuctioneerAddItemRequest Sendmsg;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecAddItemListFromLogic return but parse failed");
		return;
	}
	rsp.set_charid(req.charid());
	rsp.set_itemindex(req.iteminfo().data().index());
	rsp.set_itemnum(req.iteminfo().data().item_num());
	rsp.set_retcode(RET_SUCCESS);
	//判断是否可以出售
	AuctioneerFilterItemReq::FilterType type = GetFileterType(req.iteminfo().data().item_id());
	if (type == AuctioneerFilterItemReq::FilterType::AuctioneerFilterItemReq_FilterType_NONE)
	{
		rsp.set_retcode(RET_AUCTIONEER_ITEM_TYPE_ERROR);
	}
	else
	{
		//判断是否超出了上架上限
		uint32_t index = 0;
		AUCTIONITEMMAP::iterator iter = m_mapItem.begin();
		for (; iter != m_mapItem.end(); ++iter)
		{
			if (iter->second->GetSaleID() == req.charid())
			{
				index++;
			}
		}
		if (index >= g_constMaxSaleItem)
		{
			rsp.set_retcode(RET_AUCTIONEER_ITEM_SALE_MAX);
		}

		if (rsp.retcode() == RET_SUCCESS)  //等数据库回数据了，再通知逻辑服成功
		{
			//先发往数据库取请求分配ID
			AuctioneerItemDBData* pdate = Sendmsg.mutable_iteminfo();
			pdate->CopyFrom(req.iteminfo());
			g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_ADD_ITEM_REQ, &Sendmsg);
			return;
		}
	}
	

	//g_GetCenterService()->SendDataToLogicByCharID(req.charid(),EMODULE_ID_AUCTIONEER, CENTER_TO_LOGIC_AUCTIONEER_SALE_ITEM_RESULT, &rsp);
}


void CCenterAuctioneerMgr::OnRecReduceMoneyFromLogic(RECV_PACKAGE &package)
{
	LogicToCenterAuctioneerBuyResult req;
	AuctioneerBuyItemRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecReduceMoneyFromLogic return but parse failed");
		return;
	}

	AUCTIONITEMMAP::iterator iter = m_mapItem.find(req.itemid());
	if (iter==m_mapItem.end())
	{
		MMOLOG_FMT_ERROR("[center] OnRecReduceMoneyFromLogic return but itemid error");
		return;
	}
	rsp.set_retcode(req.retcode());
	if (req.retcode()>0) //逻辑服判断不买买
	{
		//直接返回
		
		g_GetCenterService()->SendDataToClient((CharIDType)req.charid(), (uint16_t)EMODULE_ID_AUCTIONEER, (uint16_t)CENTER_TO_CLIENT_AUCTIONEER_BUY_RESULT, &rsp);

		iter->second->SetBuyerID(0);
		return;
	}

	const ConstantConstantCfgInfo *pTax = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_AuctioneerTax);
	if (!pTax)
	{
		iter->second->SetBuyerID(0);
		return;
	}


	//给出售者发送邮件
	uint32_t allMoney = req.itemnum()*iter->second->GetPrice();
	uint32_t taxMoney = req.itemnum()*iter->second->GetPrice()*pTax->constantdata / 100.0f;
	uint32_t money = allMoney - taxMoney;
	char buff[1024] = { 0 };
	if (iter->second->GetMoneyType() == 2)
	{
		snprintf(buff, 1024, "成功拍卖道具%s*%d,成交价格%d钻石，扣除5%%的税金%d钻石，请查收收益！", iter->second->GetName().c_str(), req.itemnum(), allMoney, taxMoney);
		if (!SendMailDiamond(iter->second->GetSaleID(), "交易成功", buff, nullptr, money))
		{
			LogErrFmtPrint("CCenterAuctioneerMgr::OnRecReduceMoneyFromLogic  SendMailDiamond  to saleid fail sailid=%lu", iter->second->GetSaleID());
			return;
		}
		
		SendAuctioneerOperateLog(req.charid(), iter->second, req.itemnum(), enAuctioneerOperateType_Buy,0,allMoney);
	}
	else
	{
		snprintf(buff, 1024, "成功拍卖道具%s*%d,成交价格%d金%d银%d铜，扣除5%%的税金%d金%d银%d铜，请查收收益！", iter->second->GetName().c_str(), req.itemnum(), allMoney / 10000, (allMoney % 10000) / 100
			, allMoney % 100, taxMoney / 10000, (taxMoney % 10000) / 100, taxMoney % 100);
		if (!SendMail(iter->second->GetSaleID(), "交易成功", buff, nullptr, money))
		{
			LogErrFmtPrint("CCenterAuctioneerMgr::OnRecReduceMoneyFromLogic  SendMail  to saleid fail saleid=%lu", iter->second->GetSaleID());
			return;
		}
		

		SendAuctioneerOperateLog(req.charid(), iter->second, req.itemnum(), enAuctioneerOperateType_Buy,allMoney,0);
	}


	


	//扣成功了，给物品
	if (iter->second->GetNum()== req.itemnum())
	{
		//char buff[1024] = { 0 };
		//long long unsigned int price = req.itemnum()*iter->second->GetPrice();
		//long long unsigned int tax = price * pTax->constantdata / 100;
		iter->second->SetBuyerID(0);


		char buff[1024] = { 0 };
		snprintf(buff, 1024, "你在交易行购买的道具[%s],请查收！", iter->second->GetName().c_str());
		//给购买者发送邮件
		if (!SendMail(req.charid(), "拍卖成功", buff, iter->second->GetItemInfo()))
		{
			LogErrFmtPrint("CCenterAuctioneerMgr::OnRecReduceMoneyFromLogic  SendMail  to buyer fail buyerid=%lu", req.charid());
			return;
		}



		//发送到数据库删除该物品
		AuctioneerDeletItemRequest sendmsg;
		sendmsg.set_id(iter->first);
		g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER,DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);




		DeleteItem(req.itemid());
	}
	else
	{
		//扣除指定数量的物品，然后更新到DB
		
		ItemProtoInfo *tmpItem=(iter->second->GetItemInfo());


		//long long unsigned int price = req.itemnum()*iter->second->GetPrice();
		//long long unsigned int tax = req.itemnum()*iter->second->GetPrice() * 5 / 100;

		iter->second->SetBuyerID(0);

		char buff[1024] = { 0 };
		snprintf(buff, 1024, "你在交易行购买的道具[%s],请查收！", iter->second->GetName().c_str());

		ItemProtoInfo addItem;
		addItem.CopyFrom(*tmpItem);
		addItem.set_item_num(req.itemnum());
		if (!SendMail(req.charid(), "拍卖成功", buff, &addItem))
		{
			LogErrFmtPrint("CCenterAuctioneerMgr::OnRecReduceMoneyFromLogic  SendMail  to buyer fail buyerid=%lu", req.charid());
			return;
		}
		
		
		iter->second->SetNum(iter->second->GetNum()-req.itemnum());

		//发送更新物品消息
		AuctioneerUpdateItemReq sendmsg;
		sendmsg.set_itemid(req.itemid());
		ItemProtoInfo * pData=sendmsg.mutable_iteminfo();
		pData->CopyFrom(*tmpItem);
		g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER,DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_UPDATA_ITEM_REQ, &sendmsg);
		
	}

	g_GetCenterService()->SendDataToClient((CharIDType)req.charid(), (uint16_t)EMODULE_ID_AUCTIONEER, (uint16_t)CENTER_TO_CLIENT_AUCTIONEER_BUY_RESULT, &rsp);
	
}

void		CCenterAuctioneerMgr::onClientMessage(uint32_t actionId, RECV_PACKAGE& package, uint64_t Id /* = 0 */)
{
	//先判断该玩家等级
	const FunctionunlockFunctionUnlockCfgInfo * pConfig = g_GetFunctionunlockFunctionUnlockCfgTable()->GetFunctionunlockFunctionUnlockCfgInfo(FunctionUnlock_ID_TYPE_AUCTIONEER);
	if (!pConfig)
	{
		return;
	}

	OfflineCharacterData * pCharacterCurrent = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(Id);
	if (!pCharacterCurrent || pCharacterCurrent->GetLevel() < pConfig->unlockLevel)
	{
		//LogDebugFmtPrint("CCenterAuctioneerMgr  open level is not enough level=%d", pCharacterCurrent->GetLevel());
		return;
	}

	switch (actionId)
	{
	case CLIENT_TO_CENTER_AUCTIONEER_BUY_ITEM:
		OnRecBuyItemFromClient(package);
		break;
	case CLIENT_TO_CENTER_AUCTIONEER_SOLD_OUT:
		OnRecSoldOutFromClient(package);
		break;
	case CLIENT_TO_CENTER_AUCTIONEER_SEARCH_ITEM:
		OnRecSearchItemFromClient(package);
		break;
	case CLIENT_TO_CENTER_AUCTIONEER_FILTER_ITEM:
		OnRecFilterItemFromClient(package);
		break;
	case CLIENT_TO_CENTER_AUCTIONEER_ADD_FOCUS_ITEM:
		OnRecAddFocusFromClient(package);
		break;
	case CLIENT_TO_CENTER_AUCTIONEER_DELETE_FOCUS_ITEM:
		OnRecDeleteFocusFromClient(package);
		break;
	case CLIENT_TO_CENTER_AUCTIONEER_GETMYSALEITEM:
		OnRecGetMySaleItemList(package);
		break;
	case CLIENT_TO_CENTER_AUCTIONEER_GET_SAM_ITEM:
		OnRecGetSamItem(package);
		break;
	default:
		break;
	}
}


void CCenterAuctioneerMgr::OnRecBuyItemFromClient(RECV_PACKAGE &package)
{
	AuctioneerBuyItemReq req;
	AuctioneerBuyItemRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecBuyItemFromClient return but parse failed");
		return;
	}

	//先检查这个物品还在不在
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(req.itemid());
	if (iter==m_mapItem.end())
	{
		rsp.set_retcode(RET_PACKAGE_ITEM_NOT_EXITS);
		g_GetCenterService()->SendDataToClient((CharIDType)req.charid(), (uint16_t)EMODULE_ID_AUCTIONEER,(uint16_t)CENTER_TO_CLIENT_AUCTIONEER_BUY_RESULT,&rsp);
		return;
	}
	
	//数量够不够
	if (req.itemnum()>iter->second->GetNum())
	{
		rsp.set_retcode(RET_PACKAGE_ITEM_NUM_LACK);
		g_GetCenterService()->SendDataToClient((CharIDType)req.charid(), (uint16_t)EMODULE_ID_AUCTIONEER, (uint16_t)CENTER_TO_CLIENT_AUCTIONEER_BUY_RESULT, &rsp);
		return;
	}

	//自己不能买自己的物品
	if ((uint64_t)req.charid()==iter->second->GetSaleID())
	{
		rsp.set_retcode(RET_AUCTIONEER_CANT_BUY_MYSELF);
		g_GetCenterService()->SendDataToClient((CharIDType)req.charid(), (uint16_t)EMODULE_ID_AUCTIONEER, (uint16_t)CENTER_TO_CLIENT_AUCTIONEER_BUY_RESULT, &rsp);
		return;
	}

	if (iter->second->GetBuyerID()>0)
	{
		rsp.set_retcode(RET_AUCTIONEER_ITEM_BUYING);
		g_GetCenterService()->SendDataToClient((CharIDType)req.charid(), (uint16_t)EMODULE_ID_AUCTIONEER, (uint16_t)CENTER_TO_CLIENT_AUCTIONEER_BUY_RESULT, &rsp);
		return;
	}

	//发往逻辑服去扣钱,标记该物品已被卖
	CenterToLogicAuctioneerBuy sendmsg;
	sendmsg.set_charid(req.charid());
	sendmsg.set_type((CenterToLogicAuctioneerBuy::enmoneytype)iter->second->GetMoneyType());
	sendmsg.set_allmoney(req.itemnum()*iter->second->GetPrice());
	sendmsg.set_itemid(iter->first);
	sendmsg.set_itemnum(req.itemnum());
	if (g_GetCenterService()->SendDataToLogicByCharID(req.charid(), (uint16_t)EMODULE_ID_AUCTIONEER, (uint16_t)CENTER_TO_LOGIC_AUCTIONEER_REDUCE_MONEY, &sendmsg))
	{
		iter->second->SetBuyerID(req.charid());
	}

	LogInfoFmtPrint("CCenterAuctioneerMgr::OnRecBuyItemFromClient buy item  charid=%lu, itemid=%d,itemnum=%d,allprice=%d,pricetype=%d", req.charid(), iter->second->GetItemInfo()->item_id(), req.itemnum(), req.itemnum()*iter->second->GetPrice(), iter->second->GetMoneyType());

	g_GetRelationMgr()->UpdateRecentList(req.charid(), iter->second->GetSaleID(), RELATION_RECENT_TRADE);
}

void CCenterAuctioneerMgr::OnRecSoldOutFromClient(RECV_PACKAGE &package)
{
	AuctioneerSoldOutReq req;
	AuctioneerSoldOutRsp rsp;
	rsp.set_retcode(RET_SUCCESS);
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecBuyItemFromClient return but parse failed");
		return;
	}

	//先找到物品
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(req.itemid());
	if (iter==m_mapItem.end())
	{
		rsp.set_retcode(RET_PACKAGE_ITEM_NOT_EXITS);
	}
	else
	{
		//判断是否有人正在买
		if (iter->second->GetBuyerID()>0)
		{
			rsp.set_retcode(RET_AUCTIONEER_ITEM_BUYING);
		}
		else 
		{
			//该物品是否是该玩家的
			if (iter->second->GetSaleID() != (uint64_t)req.charid())
			{
				rsp.set_retcode(RET_AUCTIONEER_NOT_YOUR_ITEM);
			}
			else
			{

				char buff[1024] = { 0 };
				snprintf(buff, 1024, "您已取消%s的上架，系统将返还您的上架物品。", iter->second->GetName().c_str());
				//可以下架，做下架操作
				if (!SendMail(iter->second->GetSaleID(), "商品下架", buff, iter->second->GetItemInfo()))
				{
					LogErrFmtPrint("CCenterAuctioneerMgr::OnRecSoldOutFromClient  fail charid=%lu", iter->second->GetSaleID());
					return;
				}

				//发送到数据库删除该物品
				AuctioneerDeletItemRequest sendmsg;
				sendmsg.set_id(iter->first);
				g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);


				SendAuctioneerOperateLog(req.charid(), iter->second, iter->second->GetNum(), EnAuctioneerOperateType_PlayerSaleOut);

				DeleteItem(iter->first);
			}
			
			//m_mapItem.erase(iter);
			
		}
	}

	g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER, CENTER_TO_CLIENT_AUCTIONEER_SOLD_OUT_RESULT, &rsp);
}


void CCenterAuctioneerMgr::OnRecFilterItemFromClient(RECV_PACKAGE &package)
{
	AuctioneerFilterItemReq req;
	AuctioneerSearchItemRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecFilterItemFromClient return but parse failed");
		return;
	}

	if (req.type() < AuctioneerFilterItemReq::NONE || req.type() > AuctioneerFilterItemReq::en_Big_GuanZhu)
	{
		MMOLOG_FMT_ERROR("[center] OnRecFilterItemFromClient send type error type=%d",(int32_t)req.type());
		return;
	}

	
	std::vector<uint32_t> vID;

	if (req.type() == AuctioneerFilterItemReq::NONE)
	{
		//再下发当前页的物品
		SendAllItemToClient(req.charid(),req.level(),req.pagenum());
		return;
	}
	else if (req.type() == AuctioneerFilterItemReq::GuanZhu || req.type() == AuctioneerFilterItemReq::en_Big_GuanZhu) //申请关注信息
	{
		SendFocusListToClient(req.charid(),req.level(),req.pagenum()); 
		return;
	}
	else if (req.type()>AuctioneerFilterItemReq::en_Sub_Type)
	{
		AUCTIONBIGTYPE::iterator iter = m_mapBigType.find(req.type());
		if (iter!=m_mapBigType.end())
		{
			for (int i = 0; i < (int)iter->second.size();++i)
			{
				//获取该类型的所有ID
				AUCTIONEERTYPELEVEL mapLevel = m_mapTypeItem[iter->second.at(i)];
				
				for (AUCTIONEERTYPELEVEL::iterator iterLevel = mapLevel.begin(); iterLevel != mapLevel.end(); ++iterLevel)
				{
					if (req.level() <= 0 || (req.level()>0 && iterLevel->first == req.level()))
					{
						for (int i = 0; i < (int)iterLevel->second.size(); ++i)
						{
							vID.push_back(iterLevel->second.at(i));
						}
					}

				}
			}
		}
	}
	else
	{
		//获取该类型的所有ID
		AUCTIONEERTYPELEVEL mapLevel = m_mapTypeItem[req.type()];
		for (AUCTIONEERTYPELEVEL::iterator iterLevel = mapLevel.begin(); iterLevel != mapLevel.end(); ++iterLevel)
		{
			if (req.level() <= 0 || (req.level() > 0 && iterLevel->first == req.level()))
			{
				for (int i = 0; i < (int)iterLevel->second.size(); ++i)
				{
					vID.push_back(iterLevel->second.at(i));
				}
			}

		}
	}

		//uint32_t count = (req.pagenum()) * g_constPageCount;
		uint32_t requestPage = req.pagenum();
		rsp.set_pageitemnum(g_constPageCount);
		uint32_t maxPage = (uint32_t)vID.size() % g_constPageCount > 0 ? (((uint32_t)vID.size() / g_constPageCount) + 1) : (uint32_t)vID.size() / g_constPageCount;
		rsp.set_pageall(maxPage);
		if (requestPage >= maxPage)
		{
			requestPage = maxPage - 1 >0 ? maxPage - 1 : 0;
		}
		rsp.set_currentpage(requestPage);
		
		if ((uint32_t)vID.size() == 0)
		{
			//发往客户端 ,发送一空的消息回去
			g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER, CENTER_TO_CLIENT_AUCTIONEER_SEARCH_ITEM_RESULT, &rsp);
			MMOLOG_FMT_INFO("[center] OnRecFilterItemFromClient listsize is zero or send pageNum biger pagenum=%d", (int32_t)req.pagenum());
			return;
		}

		uint32_t maxIndex = (requestPage + 1)*g_constPageCount;
		uint32_t minIndex =  requestPage *g_constPageCount;
		uint32_t tmpIndex = 0;
		for (int i = (int)vID.size()-1; i >=0; --i)
		{
			if (tmpIndex>=minIndex &&  tmpIndex<maxIndex)
			{
				uint32_t itemid = vID[i];
				AUCTIONITEMMAP::iterator iter = m_mapItem.find(itemid);
				if (iter != m_mapItem.end())
				{
					AuctioneerItemData  *pData = rsp.add_iteminfo();
					iter->second->UnserializeToClient(*pData);

					AUCTIONTYPEFOCUSMAP::iterator iterFocus = m_focusMap.find(req.charid());
					if (iterFocus == m_focusMap.end())
					{
						pData->set_isfocus(0);
					}
					else
					{
						std::vector<uint32_t>::iterator iterID = find(iterFocus->second.begin(), iterFocus->second.end(), itemid);
						if (iterID==iterFocus->second.end())
						{
							pData->set_isfocus(0);
						}
						else
							pData->set_isfocus(1);
					}
						
				}
			}

			tmpIndex++;
		}

		//发往客户端
		g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER, CENTER_TO_CLIENT_AUCTIONEER_SEARCH_ITEM_RESULT, &rsp);
}


//添加关注
void CCenterAuctioneerMgr::OnRecAddFocusFromClient(RECV_PACKAGE &package)
{
	AuctioneerAddFocusIdReq req;
	AuctioneerAddFocusIdRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecAddFocusFromClient return but parse failed");
		return;
	}
	rsp.set_itemid(req.itemid());
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(req.itemid());
	if (iter==m_mapItem.end())
	{
		rsp.set_retcode(RET_PACKAGE_ITEM_NOT_EXITS);
		goto Exit0;
	}
	else
	{
		//不能添加自己的物品关注
		if (iter->second->GetSaleID()==req.charid())
		{
			rsp.set_retcode(RET_AUCTIONEER_ITEM_NOT_FOCUS_YOUSLEF);
			goto Exit0;
		}

		if (GetFileterType(iter->second->GetItemInfo()->item_id()) > AuctioneerFilterItemReq::HuFu)
		{
			rsp.set_retcode(RET_AUCTIONEER_NOT_EQUIT_ITEM);
			goto Exit0;
		}

		AUCTIONTYPEFOCUSMAP::iterator iter = m_focusMap.find(req.charid());
		if (iter!=m_focusMap.end())
		{
			std::vector<uint32_t>  pID = iter->second;
			std::vector<uint32_t>::iterator iterID = std::find(pID.begin(), pID.end(), req.itemid());
			if (iterID != pID.end())
			{
				rsp.set_retcode(RET_AUCTIONEER_IS_FOCUS_ITEM);
				goto Exit0;
			}
		}

		//开始添加
		rsp.set_retcode(RET_SUCCESS);
		m_focusMap[req.charid()].push_back(req.itemid());

		SendUpdateFocusListToDB(req.charid(),m_focusMap[req.charid()]);
	}
Exit0:
	//发往客户端
	g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER,CENTER_TO_CLIENT_AUCTIONEER_FOCUS_ADD_RESULT, &rsp);

}
//删除关注
void CCenterAuctioneerMgr::OnRecDeleteFocusFromClient(RECV_PACKAGE &package)
{
	AuctioneerDeleteFocusIdReq req;
	AuctioneerDeleteFocusIdRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecDeleteFocusFromClient return but parse failed");
		return;
	}
	rsp.set_itemid(req.itemid());
	//该商品是否存在
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(req.itemid());
	if (iter==m_mapItem.end())
	{
		rsp.set_retcode(RET_PACKAGE_ITEM_NOT_EXITS);
		goto Exit0;
	}
	else
	{
		AUCTIONTYPEFOCUSMAP::iterator iter = m_focusMap.find(req.charid());
		if (iter == m_focusMap.end())
		{
			rsp.set_retcode(RET_AUCTIONEER_NOT_IN_FOCUS_LIST);
			goto Exit0;
		}
		else
		{
			std::vector<uint32_t> & pID = iter->second;
			std::vector<uint32_t>::iterator iterID = std::find(pID.begin(), pID.end(), req.itemid());
			if (iterID == pID.end())
			{
				rsp.set_retcode(RET_AUCTIONEER_NOT_IN_FOCUS_LIST);
				goto Exit0;
			}
			else
			{
				pID.erase(iterID);
			}
				
		}
		

		rsp.set_retcode(RET_SUCCESS);

		SendUpdateFocusListToDB(req.charid(), m_focusMap[req.charid()]);
	}
Exit0:
	g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER, CENTER_TO_CLIENT_AUCTIONEER_FOCUS_DELETE_RESULT, &rsp);
}


//请求搜索结果
void CCenterAuctioneerMgr::OnRecSearchItemFromClient(RECV_PACKAGE &package)
{
	AuctioneerSearchItemReq req;
	AuctioneerSearchItemRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecSearchItemFromClient return but parse failed");
		return;
	}

	bool isJugeName = false;
	bool isJugeType = false;
	bool isJugeQuality = false;
	bool isJugeLevel = false;
	bool isJugePrice = false;
	bool isJugeDiamond = false;

	//根据条件来判断
	if (!req.itemname().empty())
	{
		isJugeName = true;
	}
	if (req.type() != 0)
	{
		isJugeType = true;
	}
	if (req.quality() != 0)
	{
		isJugeQuality = true;
	}
	if (req.levelmax() != 0)
	{
		isJugeLevel = true;
	}
	if (req.moneymax() != 0)
	{
		isJugePrice = true;
	}

	if (req.diamondmax() != 0)
	{
		isJugeDiamond = true;
	}

	uint32_t tmpCount = 0;


	uint32_t beginIndex = req.currpage()*g_constPageCount;
	uint32_t endIndex = beginIndex + g_constPageCount;

	std::vector<uint32_t >vID;
	AUCTIONITEMMAP::reverse_iterator iter = m_mapItem.rbegin();
	for (; iter != m_mapItem.rend(); ++iter)
	{
		if (isJugeName)
		{
			std::string strName = iter->second->GetName();
			string::size_type idx = strName.find(req.itemname());

			if (idx == string::npos)
			{
				continue;
			}
		}

		if (isJugeQuality)
		{
			if (iter->second->GetQuality() != req.quality())
			{
				continue;
			}
		}

		if (isJugeType)
		{
			if ((uint32_t)GetSearchType(iter->first) != (uint32_t)req.type())
			{
				continue;
			}
		}

		if (isJugeLevel)
		{
			if (iter->second->GetLevel() > req.levelmax() || iter->second->GetLevel()< req.levelmin())
			{
				continue;
			}
		}

		if ((isJugeDiamond && iter->second->GetMoneyType() == 2))
		{
			if (iter->second->GetPrice()>req.diamondmax() || (uint32_t)iter->second->GetPrice()< req.diamondmin())
			{
				continue;
			}
		}

		if (isJugePrice && iter->second->GetMoneyType() == 1)
		{
			if (iter->second->GetPrice()>req.moneymax() || (uint32_t)iter->second->GetPrice() < req.moneymin())
			{
				continue;
			}
		}

		//如果只判断金币，不判断钻石，则过虑掉钻石，否则相反
		if ((isJugeDiamond && !isJugePrice && iter->second->GetMoneyType() == 1)
			|| (!isJugeDiamond && isJugePrice && iter->second->GetMoneyType() == 2))
		{
			continue;
		}
		
		//都满足
		if (tmpCount<endIndex && tmpCount >= beginIndex) //暂时定为一次性发达不超过20个
		{
			AuctioneerItemData  *pData = rsp.add_iteminfo();
			iter->second->UnserializeToClient(*pData);

			//再看是否是关注的
			AUCTIONTYPEFOCUSMAP::iterator iterFocus = m_focusMap.find(iter->first);
			if (iterFocus == m_focusMap.end())
			{
				pData->set_isfocus(0);
			}
			else
				pData->set_isfocus(1);
		}
		vID.push_back(iter->first);
		tmpCount++;
	}

	uint32_t maxcount = (uint32_t)vID.size() % g_constPageCount >0 ? (uint32_t)vID.size() / g_constPageCount + 1 : (uint32_t)vID.size() / g_constPageCount;

	if (req.currpage() >= maxcount)
	{
		for (uint32_t i = 0; i < (uint32_t)vID.size(); ++i)
		{
			AUCTIONITEMMAP::iterator iter1 = m_mapItem.find(vID[i]);
			if (iter1!=m_mapItem.end())
			{
				AuctioneerItemData  *pData = rsp.add_iteminfo();
				iter1->second->UnserializeToClient(*pData);

				//再看是否是关注的
				AUCTIONTYPEFOCUSMAP::iterator iterFocus = m_focusMap.find(vID[i]);
				if (iterFocus == m_focusMap.end())
				{
					pData->set_isfocus(0);
				}
				else
					pData->set_isfocus(1);
			}

			if (i>g_constPageCount)
			{
				break;
			}
			
		}
		rsp.set_currentpage(0);
		rsp.set_pageitemnum(g_constPageCount);
		rsp.set_pageall(maxcount);
	}
	else
	{
		rsp.set_currentpage(req.currpage());
		rsp.set_pageitemnum(g_constPageCount);
		rsp.set_pageall(maxcount);
	}

	
	//开始发送
	g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER, CENTER_TO_CLIENT_AUCTIONEER_SEARCH_ITEM_RESULT, &rsp);
}


//请求自己发售的物品列表
void CCenterAuctioneerMgr::OnRecGetMySaleItemList(RECV_PACKAGE &package)
{
	AuctioneerMySaleItemListReq req;
	AuctioneerMysaleItemListRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecGetMySaleItemList return but parse failed");
		return;
	}

	AUCTIONITEMMAP::iterator iter = m_mapItem.begin();
	for (; iter != m_mapItem.end();++iter)
	{
		if (iter->second->GetSaleID()==req.charid())
		{
			AuctioneerItemData  *pData = rsp.add_iteminfo();
			iter->second->UnserializeToClient(*pData);
			pData->set_isfocus(0);
		}
	}

	//开始发送
	g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER,CENTER_TO_CLIENT_AUCTIONEER_GET_MYSALEITEM_RESULT, &rsp);
}

//请求相同类型的物品列表
void CCenterAuctioneerMgr::OnRecGetSamItem(RECV_PACKAGE &package)
{
	AuctioneerSamItemReq req;
	AuctioneerSamItemListRsp rsp;

	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecGetMySaleItemList return but parse failed");
		return;
	}

	AUCTIONITEMMAP::iterator iter = m_mapItem.begin();
	for (; iter != m_mapItem.end(); ++iter)
	{
		if (iter->second->GetConfigItemID() == req.itemconfigid() && iter->second->GetSaleID()!=req.charid() )
		{
			AuctioneerItemData  *pData = rsp.add_iteminfo();
			iter->second->UnserializeToClient(*pData);
			//再看是否是关注的
			AUCTIONTYPEFOCUSMAP::iterator iterFocus = m_focusMap.find(iter->first);
			if (iterFocus == m_focusMap.end())
			{
				pData->set_isfocus(0);
			}
			else
				pData->set_isfocus(1);
			
		}
	}
	//开始发送
	g_GetCenterService()->SendDataToClient(req.charid(), (uint32_t)EMODULE_ID_AUCTIONEER,CENTER_TO_CLIENT_AUCTIONEER_SAM_ITEM_LIST_RESUTL, &rsp);
}

void		CCenterAuctioneerMgr::onDBProxyMessage(uint32_t actionId, RECV_PACKAGE &package)
{
	switch (actionId)
	{
	case DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_ITEMLIST_RSP:
		OnRecItemList(package);
		break;
	case DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_ADD_ITEM_RSP:
		OnAddItemList(package);
		break;
	case DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_RSP:
		OnDeleteItemList(package);
		break;
	case DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_GET_FOCUS_LIST_RSP:
		OnGetFocusList(package);
		break;
	default:
		break;
	}
}

void CCenterAuctioneerMgr::OnRecItemList(RECV_PACKAGE &package)
{
	AuctioneerItemListResponse rsp;
	if (!rsp.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] AuctioneerItemListResponse return but parse failed....offset:%d,", rsp.iteminfo_size());
		return;
	}

	for (int i = 0; i < (int)rsp.iteminfo_size();++i)
	{
		AuctioneerItemDBData tmpdate = rsp.iteminfo().Get(i);
		if (!AddItem(&tmpdate))
		{
			MMOLOG_FMT_ERROR("rec DB itemlist  itemid=%lu,configid=%d",tmpdate.globelid(),tmpdate.data().item_id());
		}
	}

	LogDebugFmtPrint("[center] Load auctioneeritem list data finish size=%d....", (int)rsp.iteminfo_size());
}

void CCenterAuctioneerMgr::OnAddItemList(RECV_PACKAGE &package)
{
	AuctioneerAddItemResponse rsp;
	if (!rsp.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnAddItemList return but parse failed...");
		return;
	}

	if (!AddItem(rsp.mutable_iteminfo()))
	{
		MMOLOG_FMT_ERROR("[center] OnAddItemList item error itemid=%lu,configid=%d",rsp.iteminfo().globelid(),rsp.iteminfo().data().item_id());
	}
	else
	{
		//通知逻辑服更新
		CenterToLogicAuctioneerSaleResult sendMsg;
		sendMsg.set_charid(rsp.iteminfo().saleid());
		sendMsg.set_itemindex(rsp.iteminfo().data().index());
		sendMsg.set_itemnum(rsp.iteminfo().data().item_num());
		sendMsg.set_retcode(RET_SUCCESS);
		g_GetCenterService()->SendDataToLogicByCharID(rsp.iteminfo().saleid(), EMODULE_ID_AUCTIONEER, CENTER_TO_LOGIC_AUCTIONEER_SALE_ITEM_RESULT, &sendMsg);

		AUCTIONITEMMAP::iterator iter = m_mapItem.find(rsp.iteminfo().globelid());
		if (iter!=m_mapItem.end())
		{
			SendAuctioneerOperateLog(rsp.iteminfo().saleid(), iter->second, iter->second->GetNum(), EnAuctioneerOperateType_Sale);
		}
		else
		{
			MMOLOG_FMT_ERROR("[center] OnAddItemList item error itemid=%lu,configid=%d not find item", rsp.iteminfo().globelid(), rsp.iteminfo().data().item_id());
		}
	}





	//暂时先不发送
	//发送logic服，添加物品成功
	//CenterToLogicAuctioneerSale SendMsg;
	//SendMsg.set_retcode(0);
	//SendMsg.set_charid(rsp.iteminfo().saleid);

	//ActiveCharacter *pOnline = g_GetActiveCharacterMgr()->GetOnlineCharacter(rsp.iteminfo().saleid);
	//if (nullptr == pOnline)
	//{
	//	return;
	//}

	//g_GetCenterService()->SendDataToLogic(pOnline->>GetLogicServerID(), EMODULE_ID_AUCTIONEER, CENTER_TO_LOGIC_AUCTIONEER_SALE_ITEM,& SendMsg);

}
void CCenterAuctioneerMgr::OnDeleteItemList(RECV_PACKAGE &package)
{
	AuctioneerDeletItemResponse rsp;
	if (!rsp.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnDeleteItemList return but parse failed...");
		return;
	}

	if (rsp.retcode())
	{
		AUCTIONITEMMAP::iterator iter = m_mapItem.find(rsp.id());
		if (iter!=m_mapItem.end() && iter->second)
		{
			PopItemTypeMap(iter->second->GetItemInfo()->item_id(), rsp.id());
			iter->second->Unit();
			m_auctioneerItemPool->FreeObj(iter->second);
			m_mapItem.erase(iter);
		}
	}

}

void CCenterAuctioneerMgr::OnGetFocusList(RECV_PACKAGE &package)
{
	AuctioneerGerFocusListRsp rsp;
	if (!rsp.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnGetFocusList return but parse failed...");
		return;
	}
	//先清空列表
	AUCTIONTYPEFOCUSMAP::iterator iter = m_focusMap.find(rsp.charid());
	if (iter != m_focusMap.end())
	{
		m_focusMap.erase(iter);
	}
	//去掉已被买走的物品id
	std::vector<uint32_t> pID;
	for (uint32_t i = 0; i < (uint32_t)rsp.itemlist().itemid_size(); ++i)
	{
		uint32_t tmpID = rsp.itemlist().itemid().Get(i);
		AUCTIONITEMMAP::iterator iterAll = m_mapItem.find(tmpID);
		if (iterAll != m_mapItem.end())
		{
			pID.push_back(tmpID);
		}
	}

	m_focusMap[rsp.charid()] = pID;
}



//添加物品
bool CCenterAuctioneerMgr::AddItem(AuctioneerItemDBData * pDate)
{
	bool result = false;
	int32_t tmpTime = 0;
	char buff[1024] = { 0 };
	AuctioneerDeletItemRequest sendmsg;
	AUCTIONITEMMAP::iterator iter;
	CAuctioneerItem * pAuctioneerItem = nullptr;
	OfflineCharacterData * pOffLineCharacter = nullptr;
	MMOLOG_PROCESS_ERROR(pDate);

	 pAuctioneerItem = m_auctioneerItemPool->MallocObj();
	MMOLOG_PROCESS_ERROR(pAuctioneerItem);
	pAuctioneerItem->Init(*pDate);

	//上架物品时，判断该玩家是否还在，如果是删除角色的物品，自动下架
	pOffLineCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(pDate->saleid());
	if(!pOffLineCharacter)
	{
		//玩家找不到，直接下架
		//发送到数据库删除该物品
		sendmsg.set_id(pDate->globelid());
		g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);

		SendAuctioneerOperateLog(pDate->saleid(), pAuctioneerItem, pAuctioneerItem->GetNum(), EnAuctioneerOperateType_SystemSaleOut);
		m_auctioneerItemPool->FreeObj(pAuctioneerItem);
		goto Exit0;
	}


	iter = m_mapItem.find(pDate->globelid());
	if (iter==m_mapItem.end())
	{
		//看时间到了没
		tmpTime = pDate->validtime() * 60 * 60 - (Time::Now().UnixSec() - pDate->saletime());
		if (tmpTime>0)
		{
			m_mapItem[pDate->globelid()] = pAuctioneerItem;

			if (!PushItemTypeMap(pDate->data().item_id(), pDate->globelid()))
			{
				m_mapItem.erase(pDate->globelid());   //没加成功，则直接返回

				snprintf(buff, 1024, "您上架的%s已过上架期限。", pAuctioneerItem->GetName().c_str());
				//发送退信
				if (!SendMail(pDate->saleid(), "自动下架", buff, (ItemProtoInfo *)(&(pDate->data()))))
				{
					LogErrFmtPrint("CCenterAuctioneerMgr::AddItem sendmail fail charid=%lu", pDate->saleid());
					m_auctioneerItemPool->FreeObj(pAuctioneerItem);
					goto Exit0;
				}

				//发送到数据库删除该物品
				
				sendmsg.set_id(pDate->globelid());
				g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);
				//发送退信
				//SendMail(pDate->saleid(), (ItemProtoInfo *)(&(pDate->data())));

				SendAuctioneerOperateLog(pDate->saleid(), pAuctioneerItem, pAuctioneerItem->GetNum(), EnAuctioneerOperateType_SystemSaleOut);
				m_auctioneerItemPool->FreeObj(pAuctioneerItem);
				goto Exit0;
			}
			//加成功后，添加时间定时，时间到了会自动下架的
			g_GetTimerAxis()->SetTimer(pDate->globelid(), tmpTime * 1000, this, 1);
		}
		else
		{
			snprintf(buff, 1024, "您上架的%s已过上架期限。", pAuctioneerItem->GetName().c_str());
			//发送退信
			if (!SendMail(pDate->saleid(), "自动下架", buff, (ItemProtoInfo *)(&(pDate->data()))))
			{
				LogErrFmtPrint("CCenterAuctioneerMgr::AddItem sendmail fail charid=%lu", pDate->saleid());
				m_auctioneerItemPool->FreeObj(pAuctioneerItem);
				goto Exit0;
			}


			//发送到数据库删除该物品
			sendmsg.set_id(pDate->globelid());
			g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);

			SendAuctioneerOperateLog(pDate->saleid(), pAuctioneerItem, pAuctioneerItem->GetNum(), EnAuctioneerOperateType_SystemSaleOut);

			m_auctioneerItemPool->FreeObj(pAuctioneerItem);
		}
	}
	else
	{
		sendmsg.set_id(pDate->globelid());
		g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);
		LogErrFmtPrint("CCenterAuctioneerMgr::AddItem add repeate item saleid=%lu,itemconfigid=%d,itemglobelid=%lu",pDate->saleid(),pDate->data().item_id(),pDate->globelid());

		m_auctioneerItemPool->FreeObj(pAuctioneerItem);
		goto Exit0;
	}

	result = true;
Exit0:
	return result;
}

//删除物品
bool CCenterAuctioneerMgr::DeleteItem(uint64_t globelID)
{
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(globelID);
	if (iter != m_mapItem.end())
	{
		PopItemTypeMap(iter->second->GetItemInfo()->item_id(), globelID);
		
		iter->second->Unit();
		m_auctioneerItemPool->FreeObj(iter->second);

		m_mapItem.erase(iter);
	}

	return true;
}

void CCenterAuctioneerMgr::OnTimer(uint32_t nTimerID)
{

	if (enSystemTimeID_RequestDB==nTimerID)
	{
		if (g_GetCenterService()->IsConnectDBProxy() && g_GetMailMgr()->IsFinishLoad())
		{
			//向DB请求拍卖行物品列表
			AuctioneerItemListRequest req;
			if (g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_ITEMLIST_REQ, &req))
			{
				LogDebugFmtPrint("[center] start Load auctioneeritem list data....");

				g_GetTimerAxis()->KillTimer(enSystemTimeID_RequestDB,this);
			}
			else
			{
				LogDebugFmtPrint("[center] start Load auctioneeritem list data   send message error....");
			}
		}
	}
	else
	{
		AUCTIONITEMMAP::iterator iter = m_mapItem.find(nTimerID);
		if (iter != m_mapItem.end())
		{

			char buff[1024] = { 0 };
			snprintf(buff, 1024, "您上架的%s已过上架期限。", iter->second->GetName().c_str());
			//发送退信
			if (!SendMail(iter->second->GetSaleID(), "自动下架", buff, iter->second->GetItemInfo()))
			{
				LogErrFmtPrint("CCenterAuctioneerMgr::OnTimer sendmail fail charid=%lu", iter->second->GetSaleID());
				return;
			}

			//发送到数据库删除该物品
			AuctioneerDeletItemRequest sendmsg;
			sendmsg.set_id(iter->first);
			g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_DELETE_ITEM_REQ, &sendmsg);

			SendAuctioneerOperateLog(iter->second->GetSaleID(), iter->second, iter->second->GetNum(), EnAuctioneerOperateType_SystemSaleOut);

			DeleteItem(iter->first);
		}
	}
}

//发送邮件
bool CCenterAuctioneerMgr::SendMail(CharIDType destCharid ,string strMailMotif, string strContent, ItemProtoInfo * pAuctioneerItem, uint32_t money)
{
	//MailInfo info;
	//MailHead *pHead = info.mutable_mailhead();
	//pHead->set_type(MAIL_TYPE_SYSTEM);
	//pHead->set_destplayerid(destCharid);

	//if (money>0)
	//{
	//	info.set_gold(money);
	//}

	//if (pAuctioneerItem)
	//{
	//	MailAttachmentList* pMailAttachent = info.mutable_attachmentlist();
	//	ItemProtoInfo * pMailItem = pMailAttachent->add_iteminfo();
	//	pMailItem->CopyFrom(*pAuctioneerItem);
	//}
	
	//g_GetMailMgr()->Send(info);

	std::vector<ItemProtoInfo> v;

	if (pAuctioneerItem!=NULL)
	{
		v.push_back(*pAuctioneerItem);
	}
	
	if (!g_GetMailMgr()->SendSystemMail(destCharid, strMailMotif, strContent, money, 0, 0, 0, 0, v, MAIL_SOURCE_AUCTIONEER))
	{
		LogErrFmtPrint("CCenterAuctioneerMgr::SendMail fail charid=%lu,money=%d,strMailMotif=%s", destCharid, money, strContent.c_str());
		return false;
	}

	LogInfoFmtPrint("CCenterAuctioneerMgr::SendMail succeed charid=%lu,money=%d,strMailMotif=%s ", destCharid, money, strContent.c_str());

	return true;
}


bool CCenterAuctioneerMgr::SendMailDiamond(CharIDType destCharid, string strMailMotif, string strContent, ItemProtoInfo * auctioneerItem, uint32_t diamond)
{
	std::vector<ItemProtoInfo> v;

	if (auctioneerItem!=NULL)
	{
		v.push_back(*auctioneerItem);
	}

	if (!g_GetMailMgr()->SendSystemMail(destCharid, strMailMotif, strContent, 0, 0, diamond, 0, 0, v, MAIL_SOURCE_AUCTIONEER))
	{
		LogErrFmtPrint("CCenterAuctioneerMgr::SendMailDiamond  fail charid=%lu,diamond=%d,strMailMotif=%s", destCharid, diamond, strContent.c_str());

		return false;
	}

	LogInfoFmtPrint("CCenterAuctioneerMgr::SendMailDiamond  succeed charid=%lu,diamond=%d,strMailMotif=%s", destCharid, diamond, strContent.c_str());

	return true;
}



//添加分类物品
bool CCenterAuctioneerMgr::PushItemTypeMap(uint32_t configitemid, uint64_t globelID)
{
	AuctioneerFilterItemReq::FilterType type = GetFileterType(configitemid);
	if (type == AuctioneerFilterItemReq::NONE)
	{
		return false;
	}

	//找到该物品
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(globelID);
	if (iter!=m_mapItem.end())
	{
		uint32_t level=iter->second->GetLevel();
		if (m_mapTypeItem[(uint32_t)type].find(level) == m_mapTypeItem[(uint32_t)type].end())
		{
			std::vector<uint32_t>vID;
			vID.push_back(globelID);
			m_mapTypeItem[(uint32_t)type][level] = vID;
		}
		else
			m_mapTypeItem[(uint32_t)type][level].push_back(globelID);
	}

	

	return true;
}
//删除分类物品
bool CCenterAuctioneerMgr::PopItemTypeMap(uint32_t configitemid, uint64_t globelID)
{
	AuctioneerFilterItemReq::FilterType type = GetFileterType(configitemid);
	if (type == AuctioneerFilterItemReq::NONE)
	{
		return false;
	}

	//找到该物品
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(globelID);
	if (iter != m_mapItem.end())
	{
		uint32_t level = iter->second->GetLevel();
		if (m_mapTypeItem[(uint32_t)type].find(level) != m_mapTypeItem[(uint32_t)type].end())
		{
			std::vector<uint32_t> &vID = m_mapTypeItem[(uint32_t)type][level];
			std::vector<uint32_t> ::iterator iter = find(vID.begin(), vID.end(), globelID);
			if (iter != vID.end())
			{
				vID.erase(iter);
			}
		}
	}
	return true;
}
bool CCenterAuctioneerMgr::IsEquip(uint32_t configid)
{
	//先判断是装备还是物品
	char str[25] = { 0 };
	sprintf(str,"%d",configid);
	if (str[0] == '1' && str[1] == '6')  //为装备
	{
		return true;
	}

	return false;
}
//根据ID返回类型
AuctioneerFilterItemReq::FilterType CCenterAuctioneerMgr::GetFileterType(uint32_t configitemid)
{
	if (IsEquip(configitemid))  //为装备
	{
		const EquipEquipCfgInfo *pEquip = g_GetEquipEquipCfgTable()->GetEquipEquipCfgInfo(configitemid);
		if (nullptr == pEquip)
		{
			MMOLOG_FMT_ERROR("[center] nullptr == pEquip...nItemID:%u ", configitemid);
			return AuctioneerFilterItemReq::NONE;
		}
		if (pEquip->profession == ECHARACTER_PROF_WARRIOR && pEquip->position == EEquipPos_weapon)
		{
			return AuctioneerFilterItemReq::DaJian;
		}
		else if (pEquip->profession == ECHARACTER_PROF_MAGICIAN && pEquip->position == EEquipPos_weapon)
		{
			return AuctioneerFilterItemReq::FaZhang;
		}
		else if (pEquip->profession == ECHARACTER_PROF_ASSASSIN && pEquip->position == EEquipPos_weapon)
		{
			return AuctioneerFilterItemReq::BiShou;
		}
		else if (pEquip->profession == ECHARACTER_PROF_ARCHER && pEquip->position == EEquipPos_weapon)
		{
			return AuctioneerFilterItemReq::GongJian;
		}
		else if (pEquip->position == EEquipPos_clothes)
		{
			return AuctioneerFilterItemReq::YiFu;
		}
		else if (pEquip->position == EEquipPos_cloak)
		{
			return AuctioneerFilterItemReq::PiFeng;
		}
		else if (pEquip->position == EEquipPos_boot)
		{
			return AuctioneerFilterItemReq::XueZi;
		}
		else if (pEquip->position == EEquipPos_necklace)
		{
			return AuctioneerFilterItemReq::XiangLian;
		}
		else if (pEquip->position == EEquipPos_ring)
		{
			return AuctioneerFilterItemReq::JieZi;
		}
		else if (pEquip->position == EEquipPos_bracer)
		{
			return AuctioneerFilterItemReq::ShouZhuo;
		}
		else if (pEquip->position == EEquipPos_talisman)
		{
			return AuctioneerFilterItemReq::HuFu;
		}
	}
	else
	{
		const ItemItemCfgInfo *pItemInfo = g_GetItemItemCfgTable()->GetItemItemCfgInfo(configitemid);
		if (nullptr == pItemInfo)
		{
			MMOLOG_FMT_ERROR("[center] nullptr == pItem...nItemID:%u ", configitemid);
			return AuctioneerFilterItemReq::NONE;
		}

		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_drug_hp_medicine)
		{
			return AuctioneerFilterItemReq::HpYaoShui;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_drug_mp_medicine)
		{
			 return AuctioneerFilterItemReq::MpYaoShui;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_drug_sprit_food)
		{
			return AuctioneerFilterItemReq::JinlinFood;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_fuye_medicine_start && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_fuye_medicine_end)
		{
			return AuctioneerFilterItemReq::BuffYaoShui;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_medicinal_materials)
		{
			return AuctioneerFilterItemReq::YaoCai;
		}

		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_mineral)
		{
			return AuctioneerFilterItemReq::KuanShi;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_fish)
		{
			return AuctioneerFilterItemReq::Fish;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_coat)
		{
			return AuctioneerFilterItemReq::PiMao;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_scroll)
		{
			return AuctioneerFilterItemReq::JuanZhou;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_stone_begin && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_stone_end)
		{
			return AuctioneerFilterItemReq::BaoShi;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_holystone_begin && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_holystone_end)
		{
			return AuctioneerFilterItemReq::ShengYingShi;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_jl_materials_begin && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_jl_materials_end)
		{
			return AuctioneerFilterItemReq::JingLianCaiLiao;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_strenth_materials_begin && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_strenth_materials_end)
		{
			return AuctioneerFilterItemReq::QiangHuaCaiLiao;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_Equip_materials_begin && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_Equip_materials_end)
		{
			return AuctioneerFilterItemReq::EquipZhiTu;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_pet_prop_begin)
		{
			return AuctioneerFilterItemReq::JinLinShuiPian;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_pet_prop_SkillBook)
		{
			return AuctioneerFilterItemReq::JinLinSkillBook;
		}
		else if (pItemInfo->subType == (int32_t)EItemSubType::EItemSubType_pet_prop_JinHuaShi)
		{
			return AuctioneerFilterItemReq::JinLinJinHuaShi;
		}
	}

	return AuctioneerFilterItemReq::OtherItem;
}

//根据ID返回搜索类型
AuctioneerSearchItemReq::AuctionSearchType CCenterAuctioneerMgr::GetSearchType(uint64_t globelID)
{
	//根据物品ID，找到原始ID
	AUCTIONITEMMAP::iterator iter = m_mapItem.find(globelID);
	if (iter==m_mapItem.end())
	{
		return AuctioneerSearchItemReq::en_searchMax;
	}
	uint32_t configitemid = iter->second->GetItemInfo()->item_id();
	if (IsEquip(configitemid))  //为装备
	{
		const EquipEquipCfgInfo *pEquip = g_GetEquipEquipCfgTable()->GetEquipEquipCfgInfo(configitemid);
		if (nullptr == pEquip)
		{
			MMOLOG_FMT_ERROR("[center] nullptr == pEquip...nItemID:%u ", configitemid);
			return AuctioneerSearchItemReq::en_searchMax;
		}
		if (pEquip->profession == ECHARACTER_PROF_WARRIOR)
		{
			return AuctioneerSearchItemReq::en_searchZhanShiEquip;
		}
		else if (pEquip->profession == ECHARACTER_PROF_MAGICIAN)
		{
			return AuctioneerSearchItemReq::en_searchFaShiEquip;
		}
		else if (pEquip->profession == ECHARACTER_PROF_ASSASSIN)
		{
			return AuctioneerSearchItemReq::en_searchCiKeEquip;;
		}
		else if (pEquip->profession == ECHARACTER_PROF_ARCHER)
		{
			return AuctioneerSearchItemReq::en_searchSeShou;;
		}
	}
	else
	{
		const ItemItemCfgInfo *pItemInfo = g_GetItemItemCfgTable()->GetItemItemCfgInfo(configitemid);
		if (nullptr == pItemInfo)
		{
			MMOLOG_FMT_ERROR("[center] nullptr == pItem...nItemID:%u ", configitemid);
			return AuctioneerSearchItemReq::en_searchMax;
		}

		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_drug_hp_medicine && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_drug_end)
		{
			return AuctioneerSearchItemReq::en_searchYaoShui;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_medicinal_materials && pItemInfo->subType < (int32_t)EItemSubType::EItemSubType_pet_prop_begin)
		{
			return AuctioneerSearchItemReq::en_searchFuYe;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_stone_begin && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_Equip_materials_end)
		{
			return AuctioneerSearchItemReq::en_searchYancheng;
		}
		else if (pItemInfo->subType >= (int32_t)EItemSubType::EItemSubType_pet_prop_begin && pItemInfo->subType <= (int32_t)EItemSubType::EItemSubType_pet_prop_end)
		{
			return AuctioneerSearchItemReq::en_searchQITa;
		}
	}

	return AuctioneerSearchItemReq::en_searchMax;
}

void CCenterAuctioneerMgr::SendUpdateFocusListToDB(CharIDType charid, std::vector<uint32_t> &v)
{
	//发往db更新
	AuctioneerUpdateFocusListReq sendmsg;
	sendmsg.set_charid(charid);
	for (uint32_t i = 0; i < (uint32_t)v.size();++i)
	{
		sendmsg.mutable_itemlist()->add_itemid(v[i]);
	}
	g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_AUCTIONEER, DBPROXY_PROTOCOL_AUCTIONEER_AUCTIONEER_UPDATA_FOCUS_LIST_REQ, &sendmsg);
}

void CCenterAuctioneerMgr::SendAllItemToClient(CharIDType charid, uint32_t level, uint32_t pagenum)
{
	//先找出该等级所有物品ID
	uint32_t currPageNum = pagenum;
	std::vector<uint32_t> vSendID;
	AUCTIONTYPEMAP::iterator iter = m_mapTypeItem.begin();
	for (; iter != m_mapTypeItem.end();++iter)
	{
		AUCTIONEERTYPELEVEL maplevel = iter->second;
		for (AUCTIONEERTYPELEVEL::iterator iterLevel = maplevel.begin(); iterLevel != maplevel.end(); ++iterLevel)
		{
			if (level<=0 ||  (level>0 && iterLevel->first == level) )
			{
				std::vector<uint32_t> vID = iterLevel->second;
				for (int32_t i = vID.size() - 1; i >= 0; --i)
				{
					vSendID.push_back(vID[i]);
				}
			}
			
		}
		
	}

	//计算发送的页数
	uint32_t maxpage = vSendID.size() % g_constPageCount > 0 ? (vSendID.size() / g_constPageCount) + 1 : vSendID.size() / g_constPageCount;
	if (currPageNum>=maxpage)
	{
		currPageNum = maxpage-1 ;  //发客户端页面从0开始
	}

	uint32_t startIndex = currPageNum*g_constPageCount;
	uint32_t endIndex = (currPageNum + 1)* g_constPageCount;

	AuctioneerSearchItemRsp rsp;
	rsp.set_currentpage(currPageNum);
	rsp.set_pageitemnum(g_constPageCount);
	rsp.set_pageall(maxpage);
	//发送该页具体物品
	for (uint32_t i = 0;i<(uint32_t)vSendID.size();++i )
	{
		
		AUCTIONITEMMAP::iterator iter = m_mapItem.find(vSendID[i]);
		if (iter!=m_mapItem.end())
		{
			if (i >= startIndex && i < endIndex)
			{
				AuctioneerItemData  *pData = rsp.add_iteminfo();
				iter->second->UnserializeToClient(*pData);
				AUCTIONTYPEFOCUSMAP::iterator iterFocus = m_focusMap.find(charid);
				if (iterFocus == m_focusMap.end())
				{
					pData->set_isfocus(0);
				}
				else
				{
					std::vector<uint32_t>::iterator iterID = find(iterFocus->second.begin(), iterFocus->second.end(), vSendID[i]);
					if (iterID == iterFocus->second.end())
					{
						pData->set_isfocus(0);
					}
					else
						pData->set_isfocus(1);
				}
			}
		}
	}

	//发往客户端
	g_GetCenterService()->SendDataToClient(charid, (uint32_t)EMODULE_ID_AUCTIONEER, CENTER_TO_CLIENT_AUCTIONEER_SEARCH_ITEM_RESULT, &rsp);
}

void CCenterAuctioneerMgr::SendFocusListToClient(CharIDType charid, uint32_t level, uint32_t pagenum)
{
	//所有类型，往后发送
	AuctioneerSearchItemRsp rsp;
	uint32_t startIndex = pagenum*g_constPageCount;
	uint32_t endIndex = (pagenum + 1)* g_constPageCount;
	//uint32_t tmpIndex = 0;
	uint32_t tmpSendIndex = 0;
	AUCTIONTYPEFOCUSMAP::iterator iter = m_focusMap.find(charid);
	if (iter!=m_focusMap.end())
	{
		std::vector<uint32_t> &pID = iter->second;
		std::vector<uint32_t>::iterator iterID = pID.begin();
		for (; iterID != pID.end();)
		{
			AUCTIONITEMMAP::iterator iterItem = m_mapItem.find(*iterID);
			if (iterItem != m_mapItem.end())
			{
				if (level<=0 || (level>0 && iterItem->second->GetLevel() == level))
				{
					if (tmpSendIndex >= startIndex && tmpSendIndex < endIndex)
					{
						AuctioneerItemData  *pData = rsp.add_iteminfo();
						iterItem->second->UnserializeToClient(*pData);
						pData->set_isfocus(1);
					}
				}
				tmpSendIndex++;
				iterID++;
			}
			else
			{
				iterID = pID.erase(iterID);
			}
		}
	}
	
	rsp.set_currentpage(pagenum);
	rsp.set_pageitemnum(g_constPageCount);
	uint32_t maxpage = tmpSendIndex%g_constPageCount > 0 ? (tmpSendIndex / g_constPageCount) + 1 : tmpSendIndex / g_constPageCount;
	rsp.set_pageall(maxpage);

	//发往客户端
	g_GetCenterService()->SendDataToClient(charid, (uint32_t)EMODULE_ID_AUCTIONEER, CENTER_TO_CLIENT_AUCTIONEER_SEARCH_ITEM_RESULT, &rsp);
}



//log,1表示买，2表示卖，3表示自动下架，4表示手动下架
void CCenterAuctioneerMgr::SendAuctioneerOperateLog(CharIDType operateCid, CAuctioneerItem* pItem, uint32_t num, uint32_t operateType, uint32_t money , uint32_t diamond )
{
	rapidjson::Document doc;
	JsonObject obj(&doc);
	obj.AddUInt32("tid", TID_AUCTIONEER);
	obj.AddUInt32("operatetpe", operateType);
	obj.AddUInt64("salecid", pItem->GetSaleID());
	obj.AddUInt64("buycid",pItem->GetBuyerID());
	obj.AddUInt32("itemconfigid", pItem->GetConfigItemID());
	obj.AddUInt32("money", money);
	obj.AddUInt32("diamond", diamond);
	obj.AddUInt64("operatetime", Time::Now().UnixSec());
	obj.AddUInt32("zid", g_GetCenterService()->GetZoneId());
	bool bsuc = g_GetCenterService()->SendLogToLogServer(obj);
	if (bsuc == false)
		LogErrFmtPrint("player CCenterAuctioneerMgr::SendAuctioneerOperateLog log error, cid:%llu", operateCid);
}


